﻿using NFine.Application.Biz;
using NFine.Application.SystemManage;
using NFine.Code;
using NFine.Domain.Entity.SystemManage;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace NFine.Web.Areas.BizManage.Controllers
{
    public class StaticsController : ControllerBase
    {
        private ItemsDetailApp itemsDetailApp = new ItemsDetailApp();

        private UserOrderApp userOrderApp = new UserOrderApp();
        //
        // GET: /BizManage/Statics/
        

        public ActionResult MeneberIndex()
        {
            return View();
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [HandlerLogin]
        public ActionResult GetStatics(string start, string end)
        {
            DateTime dtstart = new DateTime(2000, 1, 1);
            if (!DateTime.TryParse(start, out dtstart))
            {
                dtstart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            }
            DateTime dtend = DateTime.Now;
            if (!DateTime.TryParse(end, out dtend))
            {
                dtend = DateTime.Now;
            }

            var data=userOrderApp.GetStatics(dtstart, dtend.AddDays(1));
            return Content(data.ToJson());
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [HandlerLogin]
        public ActionResult GetMemberStatics(string start, string end)
        {
            DateTime dtstart = new DateTime(2000, 1, 1);
            if (!DateTime.TryParse(start, out dtstart))
            {
                dtstart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            }
            DateTime dtend = dtstart.AddMonths(1);
            //if (!DateTime.TryParse(end, out dtend))
            //{
            //    dtend = DateTime.Now;
            //}

            var data = userOrderApp.GetMemberStatics(dtstart, dtend);
            return Content(data.ToJson());
        }



        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetGridJson(string itemId, string keyword)
        {
            var data = itemsDetailApp.GetList(itemId, keyword);
            return Content(data.ToJson());
        }
        public ActionResult MeneberForm()
        {
            return View();
        }

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetFormJson(string keyValue)
        {
            var data = itemsDetailApp.GetForm(keyValue);
            return Content(data.ToJson());
        }

        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitForm(ItemsDetailEntity itemsDetailEntity, string keyValue)
        {
            itemsDetailApp.SubmitForm(itemsDetailEntity, keyValue);
            return Success("操作成功。");
        }
    }
}
